const Base = require('../../base.js');

module.exports = class extends Base {
  async indexAction() {
    let id = this.get('id')
    if (!id) return this.fail(-1, '参数错误')

    let task = await this.model('task/index').info(id)
    if (!task) return this.fail(-1, '任务不存在')

    let userInfo = await this.session('user_info')
    let data = {task}

    if (userInfo) {
      let task_result = await this.model('task_result/index').getUserResult(userInfo._id, task._id)
      if (task_result) data.task_result = task_result
    }
    
    this.json({
      status: 200, message: 'success', data
    })
  }
};
